package com.tiantai.dashboard.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tiantai.common.annotation.Log;
import com.tiantai.common.core.controller.BaseController;
import com.tiantai.common.core.domain.AjaxResult;
import com.tiantai.common.enums.BusinessType;
import com.tiantai.dashboard.domain.TeaEnterprise;
import com.tiantai.dashboard.service.ITeaEnterpriseService;
import com.tiantai.common.utils.poi.ExcelUtil;
import com.tiantai.common.core.page.TableDataInfo;

/**
 * 企业管理Controller
 * 
 * @author handsomedog
 * @date 2024-07-25
 */
@RestController
@RequestMapping("/dashboard/enterprise")
public class TeaEnterpriseController extends BaseController
{
    @Autowired
    private ITeaEnterpriseService teaEnterpriseService;

    /**
     * 查询企业管理列表
     */
    //@PreAuthorize("@ss.hasPermi('dashboard:enterprise:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeaEnterprise teaEnterprise)
    {
        startPage();
        List<TeaEnterprise> list = teaEnterpriseService.selectTeaEnterpriseList(teaEnterprise);
        return getDataTable(list);
    }

    /**
     * 导出企业管理列表
     */
    @PreAuthorize("@ss.hasPermi('dashboard:enterprise:export')")
    @Log(title = "企业管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeaEnterprise teaEnterprise)
    {
        List<TeaEnterprise> list = teaEnterpriseService.selectTeaEnterpriseList(teaEnterprise);
        ExcelUtil<TeaEnterprise> util = new ExcelUtil<TeaEnterprise>(TeaEnterprise.class);
        util.exportExcel(response, list, "企业管理数据");
    }

    /**
     * 获取企业管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('dashboard:enterprise:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(teaEnterpriseService.selectTeaEnterpriseById(id));
    }

    /**
     * 新增企业管理
     */
    @PreAuthorize("@ss.hasPermi('dashboard:enterprise:add')")
    @Log(title = "企业管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeaEnterprise teaEnterprise)
    {
        return toAjax(teaEnterpriseService.insertTeaEnterprise(teaEnterprise));
    }

    /**
     * 修改企业管理
     */
    @PreAuthorize("@ss.hasPermi('dashboard:enterprise:edit')")
    @Log(title = "企业管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeaEnterprise teaEnterprise)
    {
        return toAjax(teaEnterpriseService.updateTeaEnterprise(teaEnterprise));
    }

    /**
     * 删除企业管理
     */
    @PreAuthorize("@ss.hasPermi('dashboard:enterprise:remove')")
    @Log(title = "企业管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(teaEnterpriseService.deleteTeaEnterpriseByIds(ids));
    }
}
